/*
 * This file is part of AXS, Annotation-XPath for SAX.
 * 
 * Copyright (c) 2013 Benjamin K. Stuhl
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.googlecode.axs;

import java.util.Map;
import java.util.Set;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

/**
 * This is the interface that the autogenerated _AXSData stubs implement to provide
 * the compiled XPath queries and callbacks for a Handler. It is completely subject to
 * change in a future version of this library. 
 * @author Ben
 *
 */
public interface AXSData {
	/**
	 * Report what version of the AXSData format this is.
	 * @return the version as 0xAAAABBBB where AAAA is the major version
	 * and BBBB is the minor version
	 */
	public abstract int getAXSDataVersion();
	
	/**
	 * Call an {@literal @}XPathStart() function.
	 * @param handler the Handler to make the call on
	 * @param xpId the index of the XPath expression in the expression data
	 * @param attrs the SAX Attributes of the the node which triggered the call
	 */
	public abstract void callXPathStart(AbstractAnnotatedHandler handler, int xpId, Attributes attrs)
				throws SAXException;

	/**
	 * Call an {@literal @}XPathEnd() function.
	 * @param handler the Handler to make the call on
	 * @param xpId the index of the XPath expression in the expression data
	 */
	public abstract void callXPathEnd(AbstractAnnotatedHandler handler, int xpId)
				throws SAXException;
	
	/**
	 * Call an {@literal @}XPath() function.
	 * @param handler the Handler to make the call on
	 * @param xpId the index of the XPath expression in the expression data
	 * @param text the concatenated TEXT elements enclosed by this element
	 */
	public abstract void callXPathText(AbstractAnnotatedHandler handler, int xpId, String text)
				throws SAXException;
	
	/**
	 * Fetch the list of precompiled XPath expressions used by the Handler. The list must be
	 * sorted so that all the {@literal @}XPath() expressions (which require the engine to capture
	 * all the TEXT elements within the match range of the expression) are first, then all the
	 * {@literal @}XPathEnd() expressions, then the {@literal @}XPathStart() expressions
	 * @return the array of compiled XPath expressions
	 */
	public XPathExpression[] getXPathExpressions();
	
	// FIXME: does it make sense to have a literals() and qNames() pointer per XPathExpression,
	// or should there be getXPathLiterals() and getXPathQNames() functions?
	
	/**
	 * Get the number of expressions which require the engine to capture TEXT elements. These
	 * expressions must be the first N elements of {@link getXPathExpressions()}.
	 * @return the number of expressions
	 */
	public int getNumberOfCapturingExpressions();
	
	// FIXME: does it take more space to have multiple getNumber*() functions, or should there
	// be just one getConstant(int constantName) function?
	
	/**
	 * Get the number of {@literal @}XPathEnd() expressions
	 * @return the number of expressions
	 */
	public int getNumberOfEndExpressions();
	
	/**
	 * Get the maximum stack depth required to evaluate any predicate in the expression array.
	 * @return the maximum stack depth required
	 */
	public int getMaximumPredicateStackDepth();
	
	/**
	 * Get the map of which tags can trigger attempts to evaluate which XPath expressions.
	 * @return a map of tag Local Names to arrays of indices into the expression array
	 */
	public Map<String, int[]> getTriggerTags();
	
	/**
	 * Get the set of tags whose attributes should be captured for later XPath expressions.
	 * @return a Set<String> of Local Names
	 */
	public Set<String> getAttributeCaptureTags();
	
	/**
	 * Get the set of tags for which the engine should record the position() values for later
	 * XPath expression evaluations.
	 * @return a Set<String> of Local Names
	 */
	public Set<String> getPositionCaptureTags();
}
